<html>
<head><meta charset="utf-8"><title>Why does rustdoc merge attributes for `impl`s? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html">Why does rustdoc merge attributes for `impl`s?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212200304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Why%20does%20rustdoc%20merge%20attributes%20for%20%60impl%60s%3F/near/212200304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html#212200304">(Oct 04 2020 at 01:51)</a>:</h4>
<p>Maybe <span class="user-mention" data-user-id="281739">@Oliver</span> will know - rustdoc has code like this in <code>inline.rs</code>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">build_impl</span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="n">cx</span>: <span class="kp">&amp;</span><span class="nc">DocContext</span><span class="o">&lt;'</span><span class="nb">_</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">did</span>: <span class="nc">DefId</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">attrs</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="n">Attrs</span><span class="o">&lt;'</span><span class="nb">_</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">ret</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">clean</span>::<span class="n">Item</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>

<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">attrs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">merge_attrs</span><span class="p">(</span><span class="n">cx</span><span class="p">,</span><span class="w"> </span><span class="n">hir_id</span><span class="p">,</span><span class="w"> </span><span class="n">load_attrs</span><span class="p">(</span><span class="n">cx</span><span class="p">,</span><span class="w"> </span><span class="n">did</span><span class="p">),</span><span class="w"> </span><span class="n">attrs</span><span class="p">);</span><span class="w"></span>
</code></pre></div>

<p>What is the <code>attrs</code> parameter here? This only runs on pub-rexports, I thought, and you can't re-export a trait implementation</p>



<a name="212200639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Why%20does%20rustdoc%20merge%20attributes%20for%20%60impl%60s%3F/near/212200639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html#212200639">(Oct 04 2020 at 02:01)</a>:</h4>
<p>You meant to ping someone else?</p>



<a name="212200646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Why%20does%20rustdoc%20merge%20attributes%20for%20%60impl%60s%3F/near/212200646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html#212200646">(Oct 04 2020 at 02:01)</a>:</h4>
<p>oh booo I thought you were <span class="user-mention silent" data-user-id="311797">Oliver Middleton</span>  <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="212200700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Why%20does%20rustdoc%20merge%20attributes%20for%20%60impl%60s%3F/near/212200700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html#212200700">(Oct 04 2020 at 02:02)</a>:</h4>
<p>I was <em>wondering</em> how you had so much time to chat on zulip lol</p>



<a name="212200715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Why%20does%20rustdoc%20merge%20attributes%20for%20%60impl%60s%3F/near/212200715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html#212200715">(Oct 04 2020 at 02:03)</a>:</h4>
<p>Sorry to disappoint <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="212203091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Why%20does%20rustdoc%20merge%20attributes%20for%20%60impl%60s%3F/near/212203091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html#212203091">(Oct 04 2020 at 03:20)</a>:</h4>
<p>somehow I ended up with this monstrosity</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">other_attrs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">attrs</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">map</span><span class="p">(</span><span class="o">|</span><span class="n">attr</span><span class="o">|</span><span class="w"> </span><span class="p">(</span><span class="n">attr</span><span class="p">,</span><span class="w"> </span><span class="nb">None</span><span class="p">))</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">chain</span><span class="p">(</span><span class="w"></span>
<span class="w">                </span><span class="n">additional_attrs</span><span class="p">.</span><span class="n">into_iter</span><span class="p">()</span><span class="w"></span>
<span class="w">                    </span><span class="p">.</span><span class="n">map</span><span class="p">(</span><span class="o">|</span><span class="p">(</span><span class="n">attrs</span><span class="p">,</span><span class="w"> </span><span class="n">id</span><span class="p">)</span><span class="o">|</span><span class="w"> </span><span class="n">attrs</span><span class="p">.</span><span class="n">iter</span><span class="p">().</span><span class="n">map</span><span class="p">(</span><span class="k">move</span><span class="w"> </span><span class="o">|</span><span class="n">attr</span><span class="o">|</span><span class="w"> </span><span class="p">(</span><span class="n">attr</span><span class="p">,</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">id</span><span class="p">))))</span><span class="w"></span>
<span class="w">                    </span><span class="p">.</span><span class="n">flatten</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">)</span><span class="w"></span>
<span class="w">            </span><span class="c1">// more cursed code follows</span>
</code></pre></div>



<a name="212203157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Why%20does%20rustdoc%20merge%20attributes%20for%20%60impl%60s%3F/near/212203157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html#212203157">(Oct 04 2020 at 03:22)</a>:</h4>
<p>also it doesn't work so that's fun</p>



<a name="212231848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Why%20does%20rustdoc%20merge%20attributes%20for%20%60impl%60s%3F/near/212231848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html#212231848">(Oct 04 2020 at 17:19)</a>:</h4>
<blockquote>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">             </span><span class="c1">// more cursed code follows</span>
</code></pre></div>

</blockquote>
<p><span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span></p>



<a name="212232836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Why%20does%20rustdoc%20merge%20attributes%20for%20%60impl%60s%3F/near/212232836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Why.20does.20rustdoc.20merge.20attributes.20for.20.60impl.60s.3F.html#212232836">(Oct 04 2020 at 17:40)</a>:</h4>
<p>this ended up as <a href="https://github.com/rust-lang/rust/pull/77519">https://github.com/rust-lang/rust/pull/77519</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>